package com.app.news.util;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.sql.SQLDataException;

public class DB {
    //用户登录时，根据用户输入的姓名学号，查询数据库是否存在数据
    //select * from account where username="" and student_id="";
    private  Context context;
    public DB(Context context) {
        this.context=context;
    }

    public  boolean loginSelect(String username, String pwd){
        MyHelper2 myHelper2=new MyHelper2(context);
        SQLiteDatabase db=myHelper2.getReadableDatabase();
        Cursor cursor=db.rawQuery("select * from account where username=?"+" and pwd=?",new String[]{username,pwd});
        if (cursor.getCount()!=0){
            return true;
        }else {
            return false;
        }
    }
    //注册
    //insert into account(username,student_id) values(?,?);
    public boolean signInInsert(String username,String pwd){
        MyHelper2 myHelper2=new MyHelper2(context);
        SQLiteDatabase db=myHelper2.getWritableDatabase();
        db.execSQL("insert into account(username,pwd) values(?,?)",new Object[]{username,pwd});
        return true;
    }

}
